//
//  APPLETabBarItem.swift
//  123
//
//  Created by pangjiaxing on 16/1/6.
//  Copyright © 2016年 pangjiaxing. All rights reserved.
//

import UIKit

class APPLETabBarItem: UITabBarItem {
    override var badgeValue :String? {
        didSet{
            if badgeValue==nil  {
                return
            }
            guard let tabBarControllert = valueForKey("_target") as? UITabBarController else{
                return
            }
            let tabBar = tabBarControllert.tabBar
            for tabBarChild in tabBar.subviews {
                if tabBarChild.isKindOfClass(NSClassFromString("UITabBarButton")!){
                    for UITabBarButtonChild in tabBarChild.subviews{
                        if UITabBarButtonChild.isKindOfClass(NSClassFromString("_UIBadgeView")!){
                            for UIBadgeViewChild in UITabBarButtonChild.subviews {
                                if UIBadgeViewChild.isKindOfClass(NSClassFromString("_UIBadgeBackground")!){
                                    UIBadgeViewChild.setValue(UIImage(named: "main_badge"), forKey: "_image")
                                    
                                }
                            }
                        }
                    }
                }
            }
        }
        
    }
}
